//
//  goodsMenuCell.m
//  ios-supplier
//
//  Created by Benlai on 15/7/31.
//  Copyright (c) 2015年 feynmanyuan. All rights reserved.
//

#import "GoodsMenuCell.h"

@implementation GoodsMenuCell
{
    UIView *iconView;
    UILabel *merchandiseNameLabel;
    CGFloat categoryWidth;
    UIImageView *imgCorner;
}

#define NAME_FONT 12
#define NAME_COLOR 0X676767
#define POINT_COLOR 0xf15353
#define RED_COLOR 0XF15353

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle: style reuseIdentifier: reuseIdentifier];
    if (self) {
        categoryWidth= 0.21*[UIScreen mainScreen].bounds.size.width;
        
        merchandiseNameLabel = [[UILabel alloc] init];
        merchandiseNameLabel.font = [UIFont systemFontOfSize: NAME_FONT];
        merchandiseNameLabel.textColor = UIColorFromRGB(0xf8392a);
        merchandiseNameLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview: merchandiseNameLabel];
        
        iconView=[[UIView alloc] initWithFrame:CGRectMake(0, 5, 4, 40)];
        iconView.backgroundColor = UIColorFromRGB(0xf8392a);
        [self addSubview:iconView];

//        imgActiveLeft=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"icon-CategoryLevel2-Active.png"]];
//        [imgActiveLeft setContentMode:UIViewContentModeScaleAspectFill];
//        [self addSubview:imgActiveLeft];
//        imgActiveLeft.backgroundColor = [UIColor colorFromHexValue: POINT_COLOR];
//        imgActiveLeft.layer.cornerRadius = 1.5;
        
//        imgActiveRight=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"icon-CategoryLevel2-Active.png"]];
//        [imgActiveRight setContentMode:UIViewContentModeScaleAspectFill];
//        [self addSubview:imgActiveRight];
//        imgActiveRight.backgroundColor = [UIColor colorFromHexValue: POINT_COLOR];
//        imgActiveRight.layer.cornerRadius = 1.5;
        
        UIImageView *line=[[UIImageView alloc]initWithFrame: CGRectMake(2, 50 - 0.5, categoryWidth - 4, 0.5)];
        [line setBackgroundColor: LineColorDefault];
        [self addSubview: line];
        
        imgCorner=[[UIImageView alloc]init];
        [imgCorner setContentMode:UIViewContentModeScaleAspectFill];
        [imgCorner setFrame:CGRectMake((categoryWidth-35), 0, 35, 35)];
        [self addSubview:imgCorner];


    }
    return self;
}

-(void) setIsActive:(bool) isActive
{
    if (isActive)
    {
        [iconView setHidden:NO];
        [merchandiseNameLabel setTextColor: UIColorFromRGB(0xf8392a)];
    }
    else
    {
        [iconView setHidden:YES];
        [merchandiseNameLabel setTextColor: [UIColor colorFromHexValue: NAME_COLOR]];
    }
}

-(void) setName:(NSString *)name
{
    
    if(name!=nil)
    {
        [merchandiseNameLabel setText: name];
        
        CGSize size = [merchandiseNameLabel.text sizeWithFont: merchandiseNameLabel.font forWidth: categoryWidth lineBreakMode: NSLineBreakByWordWrapping];
        
        merchandiseNameLabel.frame=CGRectMake((categoryWidth-size.width)/2, (55-15)/2, size.width, 15);
//        [imgActiveLeft setFrame:CGRectMake(merchandiseNameLabel.frame.origin.x-3-3, (55-3)/2, 3, 3)];
//        [imgActiveRight setFrame:CGRectMake(CGRectGetMaxX(merchandiseNameLabel.frame) +3, (55-3)/2, 3, 3)];
        
        //        [imgCorner GET:data.corner useCache:YES];
    }
}
//- (void)awakeFromNib {
//    // Initialization code
//}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
